import functools
from flask import current_app
from flask import g
from flask import session



def db_index_class(loop_index):
    if loop_index == 1:
        return "first"
    elif loop_index == 2:
        return "second"
    elif loop_index == 3:
        return "third"
    else:
        return ""



def login_user_data(view_func):
    @functools.wraps(view_func)
    def wrapper(*args,**kwargs):
        user_id = session.get("user_id")
        user = None
        from info.models import User
        try:
            if user_id:
                user = User.query.get(user_id)
        except Exception as e:
            current_app.logger.error(e)
        g.user = user

        result = view_func(*args,**kwargs)
        return result
    return wrapper


